package mx.itesm.minAFN.ut;

import java.util.ArrayList;

import mx.itesm.minAFN.AFN;
import mx.itesm.minAFN.AFNState;
import mx.itesm.minAFN.AFNStateType;

public class AFDUT {
	public static void main(String [ ] args)
	{
		
		test6();
	}
	
	private static void test9(){
		AFN afd = new AFN();
		
		AFNState one 	= new AFNState("1", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("2");
		one.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("3");
		one.addTransition("1", list);
		
		AFNState two 	= new AFNState("2", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("4");
		two.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("9");
		two.addTransition("1", list);
		
		
		AFNState three 	= new AFNState("3", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("5");
		three.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("4");
		three.addTransition("1", list);
		
		AFNState four 	= new AFNState("4", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("6");
		four.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("4");
		four.addTransition("1", list);
		
		AFNState five 	= new AFNState("5", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("5");
		five.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		five.addTransition("1", list);
		
		AFNState six 	= new AFNState("6", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("9");
		six.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		six.addTransition("1", list);
		
		AFNState seven 	= new AFNState("7", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("8");
		seven.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("5");
		seven.addTransition("1", list);
		
		AFNState eight 	= new AFNState("8", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("7");
		eight.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("6");
		eight.addTransition("1", list);
		
		AFNState nine 	= new AFNState("9", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("9");
		nine.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("8");
		nine.addTransition("1", list);
		
		afd.addState(one);
		afd.addState(two);
		afd.addState(three);
		afd.addState(four);
		afd.addState(five);
		afd.addState(six);
		afd.addState(seven);
		afd.addState(eight);
		afd.addState(nine);
		
		afd.minimize();
	}
	
	private static void test8(){
		AFN afd = new AFN();
		
		AFNState one 	= new AFNState("1", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("4");
		one.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("6");
		one.addTransition("1", list);
		
		AFNState two 	= new AFNState("2", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("1");
		two.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		two.addTransition("1", list);
		
		
		AFNState three 	= new AFNState("3", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("2");
		three.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("4");
		three.addTransition("1", list);
		
		AFNState four 	= new AFNState("4", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("6");
		four.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("5");
		four.addTransition("1", list);
		
		AFNState five 	= new AFNState("5", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("7");
		five.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("5");
		five.addTransition("1", list);
		
		AFNState six 	= new AFNState("6", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("3");
		six.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("6");
		six.addTransition("1", list);
		
		AFNState seven 	= new AFNState("7", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("3");
		seven.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		seven.addTransition("1", list);
		
		afd.addState(one);
		afd.addState(two);
		afd.addState(three);
		afd.addState(four);
		afd.addState(five);
		afd.addState(six);
		afd.addState(seven);
		
		afd.minimize();
	}	
	
	private static void test7(){
		AFN afd = new AFN();
		
		AFNState one 	= new AFNState("1", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("2");
		one.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("3");
		one.addTransition("1", list);
		
		AFNState two 	= new AFNState("2", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("4");
		two.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("5");
		two.addTransition("1", list);
		
		
		AFNState three 	= new AFNState("3", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("6");
		three.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		three.addTransition("1", list);
		
		AFNState four 	= new AFNState("4", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("4");
		four.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("5");
		four.addTransition("1", list);
		
		AFNState five 	= new AFNState("5", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("6");
		five.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		five.addTransition("1", list);
		
		AFNState six 	= new AFNState("6", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("4");
		six.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("5");
		six.addTransition("1", list);
		
		AFNState seven 	= new AFNState("7", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("6");
		seven.addTransition("0", list);
		list = new ArrayList<String>();
		list.add("7");
		seven.addTransition("1", list);
		
		afd.addState(one);
		afd.addState(two);
		afd.addState(three);
		afd.addState(four);
		afd.addState(five);
		afd.addState(six);
		afd.addState(seven);
		
		afd.minimize();
		
		
	}
	//tarea 4 - problema 3b
	private static void test6(){
		AFN afn = new AFN();
		AFNState q0 = new AFNState("q0", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("q1");
		q0.addTransition(AFN.epsilon, list);
		
		list = new ArrayList<String>();
		list.add("q2");
		q0.addTransition("a", list);
		
		AFNState q1 = new AFNState("q1", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("q0");
		q1.addTransition("a", list);
		
		AFNState q2 = new AFNState("q2", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("q1");
		q2.addTransition("a", list);
		
		list = new ArrayList<String>();
		list.add("q1");
		list.add("q2");
		q2.addTransition("b", list);
		
		afn.addState(q0);
		afn.addState(q1);
		afn.addState(q2);
		afn.minimize();
		System.out.println("minimized: "+afn.toString());
	}
	
	//presentacion 4 diapositiva 93
	private static void test5(){
		AFN afn = new AFN();
		AFNState A = new AFNState("A", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("A");
		A.addTransition("0", list);
		
		list = new ArrayList<String>();
		list.add("B");
		A.addTransition("1", list);
		
		AFNState B = new AFNState("B", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("C");
		B.addTransition("0", list);
		
		list = new ArrayList<String>();
		list.add("B");
		B.addTransition("1", list);
		
		list = new ArrayList<String>();
		list.add("A");
		B.addTransition(AFN.epsilon, list);
		
		AFNState C = new AFNState("C", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("D");
		C.addTransition("1", list);
		
		list = new ArrayList<String>();
		list.add("B");
		C.addTransition(AFN.epsilon, list);
		
		AFNState D = new AFNState("D", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("C");
		D.addTransition("0", list);
		
		list = new ArrayList<String>();
		list.add("B");
		D.addTransition(AFN.epsilon, list);
		
		afn.addState(A);
		afn.addState(B);
		afn.addState(C);
		afn.addState(D);
		afn.minimize();
	}
	
	private static void test4(){
		AFN afn = new AFN();
		AFNState A = new AFNState("A", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("C");
		A.addTransition("a", list);
		
		list = new ArrayList<String>();
		list.add("B");
		A.addTransition(AFN.epsilon, list);
		
		AFNState B = new AFNState("B", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("A");
		B.addTransition("a", list);
		
		AFNState C = new AFNState("C", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("B");
		C.addTransition("a", list);
		
		list = new ArrayList<String>();
		list.add("B");
		list.add("C");
		C.addTransition("b", list);
		
		afn.addState(A);
		afn.addState(B);
		afn.addState(C);
		afn.minimize();
	}
	
	private static void test3(){
		AFN afn = new AFN();
		AFNState A = new AFNState("A", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("C");
		A.addTransition("a", list);
		
		list = new ArrayList<String>();
		list.add("B");
		A.addTransition(AFN.epsilon, list);
		
		AFNState B = new AFNState("B", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("C");
		B.addTransition(AFN.epsilon, list);
		
		AFNState C = new AFNState("C", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("B");
		C.addTransition("a", list);
		
		list = new ArrayList<String>();
		list.add("A");
		list.add("D");
		C.addTransition(AFN.epsilon, list);
		
		AFNState D = new AFNState("D", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("A");
		D.addTransition("a", list);
		
		afn.addState(A);
		afn.addState(B);
		afn.addState(C);
		afn.addState(D);
		afn.minimize();
	}
	
	//presentacion 4 diapositiva 82
	private static void test2(){
		AFN afn = new AFN();
		AFNState A = new AFNState("A", AFNStateType.START);
		ArrayList<String> list = new ArrayList<String>();
		list.add("A");
		list.add("B");
		A.addTransition("0", list);
		
		list = new ArrayList<String>();
		list.add("A");
		list.add("D");
		A.addTransition("1", list);
		
		AFNState B = new AFNState("B", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("C");
		B.addTransition("0", list);
		
		AFNState C = new AFNState("C", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("F");
		C.addTransition("0", list);
		
		AFNState D = new AFNState("D", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("E");
		D.addTransition("1", list);
		
		AFNState E = new AFNState("E", AFNStateType.NORMAL);
		list = new ArrayList<String>();
		list.add("F");
		E.addTransition("1", list);
		
		AFNState F = new AFNState("F", AFNStateType.FINAL);
		list = new ArrayList<String>();
		list.add("F");
		F.addTransition("0", list);
		
		list = new ArrayList<String>();
		list.add("F");
		F.addTransition("1", list);
		
		afn.addState(A);
		afn.addState(B);
		afn.addState(C);
		afn.addState(D);
		afn.addState(E);
		afn.addState(F);
		
		System.out.println("Start Minimize");
		afn.minimize();
	}
	
	private static void test1(){
		
		AFN afn = new AFN();
		AFNState q0 = new AFNState("q0", AFNStateType.FINAL);
		ArrayList<String> list = new ArrayList<String>();
		list.add("q0");
		list.add("q1");
		q0.addTransition("a", list);
		
		list = new ArrayList<String>();
		list.add("q1");
		q0.addTransition("b", list);
		
		AFNState q1 = new AFNState("q1", AFNStateType.NORMAL);
		
		list = new ArrayList<String>();
		list.add("q0");
		q1.addTransition("b", list);
		
		afn.addState(q0);
		afn.addState(q1);
		System.out.println("Start Minimize");
		afn.minimize();
		
	}
}
